@extends('layouts.app')

@section('title')
    后台-搭配管理-我已搭配盒子
@stop

@section('extcss')
    <!--ext css-->
    <style>
        .btn-color {
            color: #93A2B2;
            border: 1px solid rgba(221, 226, 232, 0.49);
        }

        .table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
            vertical-align: middle;
        }
    </style>
    <!-- /ext css-->
@stop

@section('content')
    <style>
        .buttons, button, .btn {
            margin-bottom: 0;
        }
    </style>
    <!-- page content -->
    <div class="right_col" role="main">
        <div class="">
            <div class="page-title">
                <div class="title_left">
                    <h3>我已搭配盒子</h3>
                </div>

                <div class="title_right">
                    <div class="col-md-5 col-sm-12 form-group pull-right top_search">
                        <div class="input-group">
                            <input id="txtKeyWorld" type="text" class="form-control" placeholder="查找盒子编号、物流单号">
                            <span class="input-group-btn">
                                  <button id="btnSearch" class="btn btn-default" type="button"><i class="fa fa-search"
                                                                                                  title="查找盒子编号、物流单号"></i></button>
                                </span>
                        </div>
                    </div>
                    <div class="col-md-7 col-sm-12 form-group pull-right top_search text-right">
                        <a href="{{url('system/assort/index')}}" class="btn btn-round btn-default btn-color"
                           type="button" title="新增"><i class="fa fa-plus"></i></a>
                        <button id="btnSelectAll" class="btn btn-round btn-default btn-color" type="button" title="删除"
                                style="display: none;">
                            <i class="fa fa-trash"></i></button>
                        <a href="javascript:window.location.reload();" class="btn btn-round btn-default btn-color"
                           type="button" title="刷新"><i class="fa fa-refresh"></i></a>
                        <button class="btn btn-round btn-default btn-color" type="button" title="下载"
                                style="display: none;"><i
                                    class="fa fa-download"></i></button>
                        <button class="btn btn-round btn-default btn-color" type="button" title="打印"
                                style="display: none;"><i
                                    class="fa fa-print"></i></button>
                    </div>
                </div>
            </div>

            <div class="clearfix"></div>

            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>物品表</h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                </li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>

                        <div class="x_content">
                            <div class="table-responsive">
                                <table class="table table-striped jambo_table bulk_action">
                                    <thead>
                                    <tr class="column-title">
                                        <th>
                                            撤销
                                        </th>
                                        <th class="column-title">订单号</th>
                                        <th class="column-title">姓名</th>
                                        <th class="column-title">地址</th>
                                        <th class="column-title">电话</th>
                                        <th class="column-title">状态</th>
                                        <th class="column-title">归档</th>
                                        <th class="column-title">总价</th>
                                        <th class="column-title">出库物流</th>
                                        <th class="column-title">物流单号</th>
                                        <th class="column-title">回库物流</th>
                                        <th class="column-title">物流单号</th>
                                        <th class="column-title">详情</th>
                                        <th class="column-title">操作</th>
                                    </tr>
                                    </thead>

                                    <tbody>
                                    @forelse($boxs as $box)
                                        <tr class="even pointer">
                                            <td class="a-center ">
                                                @if($box->state->val<3)
                                                    <a href="#" class="btn btn-link" data-toggle="modal"
                                                       data-target="#delModel" title="删除"
                                                       data-whatever="{{$box->orderno}}">
                                                        <i class="fa fa-trash"></i>
                                                    </a>
                                                @else
                                                    <a href="#" class="btn btn-link" title="物品已经返仓作为历史不能删除" disabled>
                                                        <i class="fa fa-trash"></i>
                                                    </a>
                                                @endif
                                            </td>

                                            <td class=" ">{{\Carbon\Carbon::parse($box->created_at)->format('YmdHis')}}</td>
                                            <td class=" ">{{$box->name}}</td>
                                            <td class=" ">{{$box->address}}</td>
                                            <td class=" ">{{$box->mobile}}</td>
                                            <td class=" ">
                                                @if($box->state->val==1||$box->state->val==3||$box->state->val==4)
                                                    <button type="button" class="btn btn-success btn-xs btn-state"
                                                            data-orderno="{{$box->orderno}}"
                                                            data-state="{{$box->state->val}}">{{$box->state->key}}</button>
                                                @else
                                                    <button type="button" class="btn btn-success btn-xs btn-state"
                                                            disabled>{{$box->state->key}}</button>
                                                @endif
                                            </td>
                                            <td class=" ">
                                                @if($box->state->val==6)
                                                    @if(empty($box->remark))
                                                        <button type="button" class="btn btn-success btn-xs btn-archive"
                                                                data-box="{{$box}}" data-assort="{{$box->assorts}}"
                                                                data-toggle="modal" data-target="#archiveModal">归档
                                                        </button>
                                                    @else
                                                        <button type="button" class="btn btn-success btn-xs btn-archive"
                                                                data-orderno="{{$box->orderno}}" disabled>归档
                                                        </button>
                                                    @endif
                                                @endif
                                            </td>
                                            <td class=" ">
                                                @if($box->state->val==6)
                                                    <mark><i class="fa fa-rmb"></i>{{$box->total}}</mark>
                                                @endif
                                            </td>
                                            <td class=" ">{{$box->express_out_company}}</td>
                                            <td class=" ">{{$box->express_out_no}}</td>
                                            <td class=" ">{{$box->express_in_company}}</td>
                                            <td class=" ">{{$box->express_in_no}}</td>
                                            <td class=" "><a href="#box_{{$box->id}}" data-toggle="collapse"
                                                             aria-expanded="false" aria-controls="box_{{$box->id}}"
                                                             title="展开详细信息"><i class="fa fa-ellipsis-h"></i></a></td>
                                            <td class=" "><a href="{{url('system/assort/print/'.$box->orderno)}}"
                                                             title="票据打印"><i class="fa fa-print fa-1x"></i></a></td>
                                        </tr>
                                        <tr class="collapse" id="box_{{$box->id}}">
                                            <td colspan="15">
                                            @foreach($box->Assorts as $assort)
                                                <!--item-->
                                                    <div class="col-md-3 col-xs-12 widget widget_tally_box">
                                                        <div class="x_panel ui-ribbon-container">

                                                            <div class="x_content">
                                                                <div style="text-align: center; margin-bottom: 17px">
                                                                    <img class="img-thumbnail"
                                                                         src="{{asset("upload/images/".($assort->img ==null ? "default.png":pathinfo($assort->img)["basename"]))}}">
                                                                </div>
                                                                <div>
                                                                    <ul class="list-inline widget_tally">
                                                                        <li>
                                                                            <div class="form-group">
                                                                                <label class="cartlabel control-label col-md-4 col-sm-3 col-xs-3">尺码</label>
                                                                                <div class="col-md-8 col-sm-9 col-xs-9">
                                                                                    <span class="lead"><mark>{{$assort->size}}</mark></span>
                                                                                </div>
                                                                            </div>
                                                                        </li>
                                                                        <li>
                                                                            <div class="form-group">
                                                                                <label class="cartlabel control-label col-md-4 col-sm-3 col-xs-3">颜色</label>
                                                                                <div class="col-md-8 col-sm-9 col-xs-9">
                                                                                    <span class="lead"><mark>{{$assort->color}}</mark></span>
                                                                                </div>
                                                                            </div>
                                                                        </li>
                                                                        <li>
                                                                            <div class="form-group">
                                                                                <label class="cartlabel control-label col-md-4 col-sm-3 col-xs-3">分类</label>
                                                                                <div class="col-md-8 col-sm-9 col-xs-9">
                                                                                    <span class="lead"><mark>{{$assort->category}}</mark></span>
                                                                                </div>
                                                                            </div>
                                                                        </li>
                                                                        <li>
                                                                            <div class="form-group">
                                                                                <label class="cartlabel control-label col-md-4 col-sm-3 col-xs-3">数量</label>
                                                                                <div class="col-md-8 col-sm-9 col-xs-9">
                                                                                    <span class="lead"><mark>{{$assort->number}}</mark></span>
                                                                                </div>
                                                                            </div>
                                                                        </li>
                                                                        <li>
                                                                            <div class="form-group">
                                                                                <label class="cartlabel control-label col-md-4 col-sm-3 col-xs-3">状态</label>
                                                                                <div class="col-md-8 col-sm-9 col-xs-9">
                                                                                    <span class="lead"><mark>{{$assort->state->key}}</mark></span>
                                                                                </div>
                                                                            </div>
                                                                        </li>
                                                                    </ul>
                                                                    <div class="clearfix"></div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <!-- /item-->
                                                @endforeach
                                            </td>
                                        </tr>
                                    @empty
                                        <tr class="even pointer">
                                            <td class="a-center text-center" colspan="15">
                                                没有查到记录
                                            </td>
                                        </tr>
                                    @endforelse
                                    </tbody>
                                    <tfoot>
                                    　　
                                    <tr>
                                        　　
                                        <td colspan="15">
                                            　　　@if($errors->any())
                                                <ul class="list-group">
                                                    @foreach($errors->all() as $error)
                                                        <li class="list-group-item list-group-item-danger">{{$error}}</li>
                                                    @endforeach
                                                </ul>
                                            @endif
                                        </td>
                                        　　
                                    </tr>
                                    　
                                    </tfoot>
                                </table>
                            </div>
                            <div class="row">
                                <div class="col-md-5 col-xs-12 col-sm-12 col-md-offset-5">{!! $boxs->links() !!}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /page content -->
    <!--goods delete model-->
    <div id="delModel" class="modal fade bs-delete-sm" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel4">撤销提醒</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">您确定要撤销这行记录吗？</p>
                </div>
                <div class="modal-footer">
                    <div class="row">
                        <div class="col-md-6">
                            <button id="btnModelDel" type="button" class="btn btn-default btn-block">撤销</button>
                        </div>
                        <div class="col-md-6">
                            <button type="button" class="btn btn-default btn-block" data-dismiss="modal">关闭</button>
                        </div>
                    </div>


                </div>
            </div>
        </div>
    </div>
    <!-- /goods remark model-->

    <!-- Archive Modal -->
    <div class="modal fade" id="archiveModal" tabindex="-1" role="dialog" aria-labelledby="archiveModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="archiveModalLabel">Modal title</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal">
                        <div class="control-group">
                            <label class="control-label col-md-2 col-sm-2 col-xs-12">归档标签</label>
                            <div class="col-md-10 col-sm-10 col-xs-12">
                                <input id="tags_1" type="text" class="tags form-control" value="
                                @foreach($tags as $tag)
                                {{$tag->label.','}}
                                @endforeach
                                        " disabled/>
                                <div id="suggestions-container"
                                     style="position: relative; float: left; width: 250px; margin: 10px;"></div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success">提交归档</button>
                </div>
            </div>
        </div>
    </div>
    <!-- /Archive Modal -->

@stop

@section('extjs')
    <!--ext js-->
    <!-- jQuery Tags Input -->
    <script src="{{asset("vendors/jquery.tagsinput/src/jquery.tagsinput.js")}}"></script>
    <!-- jQuery Tags Input -->
    <script>
        function onAddTag(tag) {
            $.ajax({
                url: "{{url('system/tags/ajaxadd')}}"
                , async: true
                , type: "POST"
                , data: {"tag": tag}
                , headers: {'X-CSRF-TOKEN': '{{ csrf_token() }}'}
                , success: function (result) {
                }
            });
        }

        function onRemoveTag(tag) {
            alert("Removed a tag: " + tag);
        }

        function onChangeTag(input, tag) {
            alert("Changed a tag: " + tag);
        }

        $(document).ready(function () {
            $('#tags_1').tagsInput({
                width: 'auto',
                'onAddTag': onAddTag,
            });
        });
    </script>
    <!-- /jQuery Tags Input -->
    <!--Only row delete-->
    <script>
        $('#delModel').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var recipient = button.data('whatever');

            $("#btnModelDel").on('click', function () {
                $.ajax({
                    url: "{{url('system/box/')}}" + "/" + recipient
                    , async: true
                    , type: "DELETE"
                    , headers: {'X-CSRF-TOKEN': '{{ csrf_token() }}'}
                    , success: function () {
                        $('#delModal').modal('hide');
                        window.location.reload();
                    }
                });
            })
        });

    </script>
    <!-- /Only row delete-->

    <!--Select all delete-->
    <script>
        $("#btnSelectAll").click(function () {

            $('#delModel').modal('show');

            $("#btnModelDel").on('click', function () {

                $(".bulk_action input[name='table_records']:checked").each(function (index, item) {
                    $.ajax({
                        url: "{{url('system/goods/')}}" + "/" + $(item).data('whatever')
                        , async: true
                        , type: "DELETE"
                        , headers: {'X-CSRF-TOKEN': '{{ csrf_token() }}'}
                        , success: function () {
                            $('#delModal').modal('hide');
                            window.location.reload();
                        }
                    });
                });
            });
        });

    </script>
    <!-- /Select all delete-->
    <!--change state-->
    <script>
        $(".btn-state").click(function () {

            var datajson = {
                "orderno": $(this).attr('data-orderno'),
                "state": $(this).attr('data-state')
            };

            $.ajax({
                url: "{{url('system/assort/ajaxchangestate')}}"
                , async: true
                , type: "POST"
                , data: datajson
                , headers: {'X-CSRF-TOKEN': '{{ csrf_token() }}'}
                , success: function (result) {
                    if (result.error !== undefined) {
                        alert("状态无法切换");
                        return false;
                    } else {
                        window.location.reload();
                    }
                }
            });
        });
    </script>
    <!--/ change state-->
    <!--search key world-->
    <script>
        $("#btnSearch").click(function () {
            var keyworld = $("#txtKeyWorld").val();

            window.location.href = '/system/assort/myboxs/' + keyworld;
        });
    </script>
    <!--search key world-->

    <!--archive-->
    <script>
        $('#archiveModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var box = button.data('box');
            var modal = $(this);
            modal.find('.modal-title').text("归档" + "【" + box.name + "】" + "盒子");
            modal.find('.btn-success').click(function () {

                var datajson = {"remark": $('#tags_1').val(), "orderno": box.orderno};
                $.ajax({
                    url: "{{url('system/box/remark/')}}"
                    , async: true
                    , type: "POST"
                    , data: datajson
                    , headers: {'X-CSRF-TOKEN': '{{ csrf_token() }}'}
                    , success: function (result) {
                        if (result.error !== undefined) {
                            alert("状态无法切换");
                            return false;
                        } else {
                            window.location.reload();
                        }
                    }
                });
            });
        })
    </script>
    <!--/archive-->
    <!-- /ext js-->
@stop